package com.gking.aiService.common;

import java.util.Map;

/**
 * 基于ThreadLocal封装工具类，用户保持和获取当前登录用户 id
 */
public class BaseContext {

    // 用于存储当前用户id
    private static ThreadLocal<String> threadLocal = new ThreadLocal<>();

    /**
     * 设置值
     *
     * @param id
     */
    public static void setCurrentId(String id) {
        threadLocal.set(id);
    }

    /**
     * 获取值
     *
     * @return
     */
    public static String getCurrentId() {
        return threadLocal.get();
    }


    // 存储请求响应体
    private static final ThreadLocal<String> threadLocalTwo = new ThreadLocal<>();

    public static void setResponseBody(String object) {
        threadLocalTwo.set(object);
    }

    public static String getResponseBody() {
        return threadLocalTwo.get();
    }


    // 销毁存储的数据，以防内存泄漏等问题
    public static void destroy() {
        threadLocal.remove();
        threadLocalTwo.remove();
    }

}
